// 该文件专门用于创建整个应用的路由器
import VueRouter from 'vue-router'
// 引入组件
import About from "@/views/About";
import Home from "@/views/Home";
import News from "@/views/News";
import Message from "@/views/Message";
import Detail from "@/views/Detail";

// 创建并且暴露一个路由器
const router = new VueRouter({
    routes: [
        {
            name: 'guanyu',
            // 一级路由的 path 需要再加上斜杠 /
            path: '/about',
            component: About,
            meta: {isAuth:true, title:'关于'}
        },
        {
            name: 'zhuye',
            path: '/home',
            component: Home,
            meta: {title: '主页'},
            // 二级路由的 path 不需要再加上斜杠 /
            children: [
                {
                    name: 'xinwen',
                    path: 'news',
                    component: News,
                    meta: {isAuth: true, title: '新闻'}
                },
                {
                    name: 'xiaoxi',
                    path: 'message',
                    component: Message,
                    meta: {isAuth: true, title: '消息'},
                    children: [
                        {
                            name: 'xiangqing',
                            path: 'detail',
                            component: Detail,

                            // props 的第三种写法
                            props($route) {
                                return {id:$route.query.id, title:$route.query.title}
                            },
                            meta: {isAuth: true, title: '详情'},
                        }
                    ]
                }
            ]
        }
    ]
});

export default router